package codediff.controller;

import codediff.parse.report.Counter;
import codediff.parse.report.CoverageReport;
import codediff.service.CodeService;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("codes")
public class CodeController {
    @Autowired
    private CodeService codeService;

    @PostMapping("save")
    public ResponseEntity<Void> save(@RequestBody CodeSaveDto codeSaveDto) throws GitAPIException {
        codeService.save(codeSaveDto);
        return ResponseEntity.noContent().build();
    }

    @GetMapping
    public ResponseEntity<Mono<CoverageReport>> getReport(String repoPath, String currentLabel, String baseLabel) {
        return ResponseEntity.ok(codeService.getReport(repoPath, baseLabel, currentLabel));
    }

    @GetMapping("/test1")
    public ResponseEntity<Mono<List<Counter>>> test1(String repoPath, String currentLabel, String baseLabel) {
        return ResponseEntity.ok(codeService.test1(repoPath, baseLabel, currentLabel));
    }
}
